<template>
  <el-dialog
    title="审核不通过"
    :visible.sync="auditFailDialogData.isShow"
    width="480px"
    top="35vh"
    :before-close="labelHandleClose"
    @close="closeAuditFailDialog"
  >
    <el-form
      ref="ruleForm"
      height="500px"
      :model="ruleForm"
      label-width="120px"
      label-position="right"
    >
      <el-form-item label="理由:" label-width="90px" prop="remark">
        <el-input
          v-model="ruleForm.remark"
          type="textarea"
          :rows="5"
          placeholder=""
          class="textarea"
          resize="none"
        ></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button plain @click="cancelLabel">关 闭</el-button>
      <el-button type="success" class="submitPass" @click="submit"
        >提 交</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
export default {
  props: ['auditFailDialogData', 'from'], // from 来源: pubNotice 发布审核
  data() {
    return {
      ruleForm: {
        remark: '' // 审核不通过原因
      },
      noticeId: ''
    }
  },
  mounted() {
    this.noticeId =
      this.auditFailDialogData.noticeId || this.auditFailDialogData.params
  },
  methods: {
    labelHandleClose(done) {
      this.cancelLabel()
      done()
    },
    cancelLabel() {
      // 关闭前清空
      this.auditFailDialogData.isShow = false
    },
    // 关闭对话框回调
    closeAuditFailDialog() {
      this.ruleForm.remark = ''
    },
    // 提交不通过请求
    submit() {
      if (this.ruleForm.remark.length > 200) {
        this.$alert('不通过原因不可以超过200字', '系统提示', {
          confirmButtonText: '确定',
          type: 'error'
        })
        return
      }
      let url = ''
      if (this.from === 'pubNotice') {
        url = `/notices/${this.noticeId}/audit/published/unpass?remark=${this.ruleForm.remark}`
      } else if (this.from === 'opeNotice') {
        url = `/notices/${this.noticeId}/audit/operate/unpass?remark=${this.ruleForm.remark}`
      }
      let params = ''
      this.pubRequire(
        'put',
        url,
        params,
        (response) => {
          this.$emit('refresh')
          this.auditFailDialogData.isShow = false
        },
        (response) => {
          this.$message({
            message: response.message,
            type: 'warning'
          })
          this.auditFailDialogData.isShow = false
        }
      )
    }
  }
}
</script>
<style lang="less" scoped>
// .textarea {
//   margin-bottom: 50px;
// }
</style>
